package procilege.impl.formatter;

import org.apache.solr.util.OpenBitSet;

import procilege.compute.ExprFormatTraveller;
import procilege.compute.PlaceType;
import procilege.compute.PlaceTypeMetadata;

@PlaceTypeMetadata(type = OpenBitSet.class)
public class OpenBitSetFormatter implements PlaceType<ExprFormatTraveller> {

	public void visit(ExprFormatTraveller tr, Object place) {

		StringBuilder sb = tr.getBuilder();

		OpenBitSet bs = (OpenBitSet) place;

		long i = bs.nextSetBit(0);
		if (i >= 0) {
			sb.append(i);
			i = bs.nextSetBit(i + 1);
			while (i >= 0) {
				sb.append(',');
				sb.append(i);
				i = bs.nextSetBit(i + 1);
			}
		}
	}
}